package toman.jpa;

import toman.Index;
import toman.Ref;
import toman.orm.TO;

import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
import java.util.List;

@TO(
    id = "p.id=:photoId",
    read = "select p.id, p.name, p.description, p.created, p.album.name from Photo p",
    write = "update Photo p set p.name=:photoName, p.description=:photoDescription")
public class BasicPhotoAlbumWithDateTO {

    @Index(0)
    private int photoId;
    @Index(1)
    private String photoName;
    @Index(2)
    private String photoDescription;

    private String albumName;

    // Temporal annotation is necessary always when the field is used as a parameter to a context query
    @Temporal(TemporalType.DATE)
    @Index(3)
    private Date photoCreated;

    @Ref("p.created=:photoCreated")
    private List<BasicPhotoAlbumTO> sameDatePhotos;

    @Index(4)
    public void setAlbumName(String albumName) {
        this.albumName = albumName + "-featured";
    }

    public String getAlbumName() {
        return albumName;
    }

    public int getPhotoId() {
        return photoId;
    }

    public void setPhotoId(int photoId) {
        this.photoId = photoId;
    }

    public String getPhotoName() {
        return photoName;
    }

    public void setPhotoName(String photoName) {
        this.photoName = photoName;
    }

    public String getPhotoDescription() {
        return photoDescription;
    }

    public void setPhotoDescription(String photoDescription) {
        this.photoDescription = photoDescription;
    }

}
